/*
 ID: brodyzt1
 PROG: transform
 LANG:C++
 */

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

bool is90Rotation(char pattern1[10][10],char pattern2[10][10], int length)
{
    bool isRight90Rotation = true;
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[j][length - (i + 1)])) {
                isRight90Rotation = false;
                break;
            }
        }
    }
    return isRight90Rotation;
}

bool is180Rotation (char pattern1[10][10],char pattern2[10][10], int length)
{
    bool is180Rotation = true;
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[length - (i + 1)][length - (j + 1)])) {
                is180Rotation = false;
                break;
            }
        }
    }
    
    return is180Rotation;
}

bool is270Rotation (char pattern1[10][10],char pattern2[10][10], int length)
{
    bool is270Rotation = true;
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[length - (j + 1)][i])) {
                is270Rotation = false;
                break;
            }
        }
    }
    return is270Rotation;
}

bool isReflection (char pattern1[10][10],char pattern2[10][10], int length)
{
    bool isReflection = true;
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[i][length - (j + 1)])) {
                isReflection = false;
                break;
            }
        }
    }
    return isReflection;
}

bool isCombo (char pattern1[10][10],char pattern2[10][10], int length)
{
    bool isCombo1 = true;
    bool isCombo2 = true;
    bool isCombo3 = true;
    
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[j][i])) {
                isCombo1 = false;
                break;
            }
        }
    }
    
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[length - (i+1)][j])) {
                isCombo2 = false;
                break;
            }
        }
    }
    
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[length - (j + 1)][length - (i + 1)])) {
                isCombo3 = false;
                break;
            }
        }
    }
    
    
    return isCombo1 || isCombo2 || isCombo3;
}

bool isNoChange (char pattern1[10][10],char pattern2[10][10], int length)
{
    bool isNoChange = true;
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            if (!(pattern1[i][j] == pattern2[i][j])) {
                isNoChange = false;
                break;
            }
        }
    }
    
    return isNoChange;
}

int main(int argc, const char * argv[])
{
    ifstream input;
    input.open("transform.in");
    int length;
    input >> length;
    char pattern1[10][10];
    
    char pattern2[10][10];
    
    for (int i = 0; i < length; i++) {
        string tempRow;
        input >> tempRow;
        for (int j = 0; j < length; j++) {
            pattern1[i][j] = tempRow[j];
        }
    }
    for (int i = 0; i < length; i++) {
        string tempRow;
        input >> tempRow;
        for (int j = 0; j < length; j++) {
            pattern2[i][j] = tempRow[j];
        }
    }
    /*for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            cout << pattern1[i][j];
        }
        cout << "\n";
    }
    for (int i = 0; i < length; i++) {
        for (int j = 0; j < length; j++) {
            cout << pattern2[i][j];
        }
        cout << "\n";
    }*/
    ofstream output;
    output.open("transform.out");
    if(is90Rotation(pattern1, pattern2, length))
    {
        output << "1\n";
    }
    else if (is180Rotation(pattern1, pattern2, length))
    {
         output << "2\n";
    }
    else if (is270Rotation(pattern1, pattern2, length))
    {
        output << "3\n";
    }
    else if (isReflection(pattern1, pattern2, length))
    {
        output << "4\n";
    }
    else if (isCombo(pattern1, pattern2, length))
    {
        output << "5\n";
    }
    else if (isNoChange(pattern1, pattern2, length))
    {
        output << "6\n";
    }
    else {
        output << "7\n";
    }
    output.close();
    input.close();
}

